import ChatTTS
import torch
import torchaudio

chat = ChatTTS.Chat()
chat.load(source="local", custom_path='model/ChatTTS', compile=True)  # Set to True for better performance

texts = ["你好啊，你叫什么名字，你会说中文吗"]

wavs = chat.infer(texts)

for i in range(len(wavs)):
    """
    In some versions of torchaudio, the first line works but in other versions, so does the second line.
    """
    try:
        torchaudio.save(
            f"basic_output{i}.wav", torch.from_numpy(wavs[i]).unsqueeze(0), 24000
        )
    except:
        torchaudio.save(f"basic_output{i}.wav", torch.from_numpy(wavs[i]), 24000)
